package com.huc.tools;

//import com.huc.tools.kafka.consumer.ConsumerStart;
//import com.huc.tools.mq.consumer.RabbitmqStart;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huc.tools.tools.redis.RedisTools;
//import com.whalin.MemCached.MemCachedClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Random;

@ComponentScan("com.huc.tools")
@SpringBootApplication
@RestController
public class ToolsApplication implements CommandLineRunner{

//    @Autowired
//    private MongoClient getMongoClient;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private RedisTemplate redisTemplate;

//    @Autowired
//    MemCachedClient memCachedClient;
//
//    @Autowired
//    private ConsumerStart start;
//
//    @Autowired
//    private RabbitmqStart rabbitmqStart;

    public static void main(String[] args) {
        SpringApplication.run(ToolsApplication.class, args);
    }

    @Override
    public void run(String... strings) throws Exception {


    }

    @RequestMapping("/hset")
    public void hset(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id","1");
        jsonObject.put("resource","/test/test3");
        jsonObject.put("count","1");
        RedisTools.hset(redisTemplate,"test","/test/test2",jsonObject.toJSONString());
    }

    @RequestMapping("/hget")
    public String hget(String item){
        return RedisTools.hget(redisTemplate,"test",item)+"";
    }

    @RequestMapping("/lpush_time")
    public void test(){
        RedisTools.lpush(redisTemplate,"test","ewewewewe"+new Random().nextInt(9999),60);
    }

    @RequestMapping("/hgetList")
    public void hgetList(){
        List<String> list = RedisTools.hgetList(redisTemplate,"test");
        list.forEach(s->{
            JSONObject jsonObject = JSONObject.parseObject(s);
            System.out.println(jsonObject.getString("resource"));
            System.out.println(jsonObject.toJSONString());
        });
    }

    @RequestMapping("/hgetmap")
    public void hgetmap(){
        Map<String,Object> map = RedisTools.getMap(redisTemplate,"test");
        System.out.println(map);
    }

    @RequestMapping("/lpop")
    public void test2(String key){
        System.out.println(RedisTools.lpop(redisTemplate,key));
    }
}
